package com.zly.offer.backend.controller;

import com.zly.offer.backend.entity.AICharacter;
import com.zly.offer.backend.service.CharacterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/character")
public class CharacterController {
    @Autowired
    private CharacterService characterService;

    @GetMapping("/search")
    public List<AICharacter> search() {
        return characterService.list();
    }

    @PostMapping("/add")
    public ResponseEntity<Boolean> add(@RequestBody AICharacter character) {
        return ResponseEntity.ok(characterService.save(character));
    }

    @PostMapping("/addAll")
    @Transactional
    public ResponseEntity<Boolean> addAll(@RequestBody List<AICharacter> characterList) {
        return ResponseEntity.ok(characterService.saveBatch(characterList));
    }
}
